<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../../css/aui/aui.css" />
    <title>验证码登录</title>
    <style>
        html,
        body {
            background: #fff;
        }

        #app {
            font-size: 0.7rem;
        }

        .aui-checkbox {
            width: 0.8rem;
            height: 0.8rem;
            margin-top: 0.1rem;
        }

        .row_flex {
            display: flex;
            align-items: center;
        }

        .inp {
            border-bottom: 1px solid #eee;
            margin-top: 0.5rem;
        }

        .active {
            color: #0689FB;
        }

        .btn {
            background: #0689FB;
            width: 80%;
            height: 2rem;
            text-align: center;
            line-height: 2rem;
            color: #fff;
            margin: 2rem auto 0;
            border-radius: 0.2rem;
        }

        .get_code {
            width: 9.5rem;
            color: #0689FB;
            text-align: center;
            border: 1px solid #0689FB;
            border-radius: 0.2rem;
        }
    </style>
</head>

<body>
    <div id="app">
        <div style="position:relative;">
            <img src="../../image/img/denglu_bg.png" alt="">
            <div style="position:absolute;top:0;left:0;width:100%;">
                <div style="width:5rem;height:5rem;margin:4rem auto 0;overflow:hidden;padding:0.2rem;border:1px solid #fff;border-radius:50%;">
                    <img src="../../image/icon/logo2.png" alt="">
                </div>
            </div>
        </div>
        <div style="padding:1rem 2rem;">

            <div class='row_flex inp'>
                <img src="../../image/icon/denglu01.png" style="width:1.5rem;height:1.5rem;" alt="">
                <input type="text" id="user_tel" v-model="userInfo.user_tel" placeholder="请输入手机号">
            </div>
            <div class='row_flex inp'>
                <img src="../../image/icon/denglu03.png" style="width:1.2rem;height:1.2rem;margin:0 0.2rem;" alt="">
                <input type="text" id="captcha" v-model="userInfo.captcha" placeholder="请输入验证码">
                <div class="get_code" onclick="send_code(this)">获取验证码</div>
            </div>
            <div class="row_flex" style="justify-content:space-between;margin:0.8rem 0;">
                <div class="active" @click="openWin('login')">用密码登录</div>
            </div>

            <div class="btn" @click="login()">登录</div>
        </div>
        <footer class="row_flex" style="justify-content:center;">
            <div class="aui-margin-r-5" @click="openWin('register')">注册</div>
            <!-- |<div class="aui-margin-l-5" @click="openWin('reset_pwd')">忘记密码</div> -->
        </footer>
    </div>
</body>
<script src="../../script/api.js" charset="utf-8"></script>
<script src="../../script/common/jquery-3.3.1.min.js" charset="utf-8"></script>
<script src="../../script/common/check.js" charset="utf-8"></script>
<script src="../../script/common/common.js" charset="utf-8"></script>
<script src="../../script/common/config.js" charset="utf-8"></script>
<script src="../../script/common/vue.min.js" charset="utf-8"></script>
<script>
    apiready = function() {
        api.parseTapmode();
        vm.userInfo.user_tel = get_local('user_tel');

    }
    var vm = new Vue({
        el: "#app",
        data: {
            userInfo: {
                user_tel: '',
                captcha: '',
            }
        },
        methods: {
            login() {
                var that = this;
                if (!is_define(this.userInfo.user_tel)) {
                    $toast("手机号不能为空");
                    return;
                } else if (!checkMobile(this.userInfo.user_tel)) {
                    $toast("请输入正确的手机号码");
                    return;
                } else if (!is_define(this.userInfo.captcha)) {
                    $toast("请输入验证码");
                    return;
                } else if (this.userInfo.captcha.length < 4) {
                    $toast("验证码最少为4位");
                    return;
                }

                _ajax(Config.api.LoginCaptchaLogin, this.userInfo, function(ret) {
                    if (ret.code === 200) {
                        $toast("登录成功");
                        set_local('userInfo', ret.data);
                        that.execScript();
                        setTimeout(function() {
                            var winInfo = {
                                name: 'main',
                                url: '../main.html'
                            };
                            // 打开页面
                            open_w(winInfo.name, winInfo.url, {}, false, true);
                        }, 500);
                    }
                });

            },
            execScript() {
                // 设置frame组选中项
                api.execScript({
                    name: 'main',
                    script: 'setSelectOption(0);'
                });
                api.execScript({
                    name: 'main',
                    frameName: 'my',
                    script: 'vm.init()'
                });
            },
            openWin(name) {
                var winInfo = {
                    register: {
                        name: 'register',
                        url: './register.html'
                    },
                    reset_pwd: {
                        name: 'reset_pwd',
                        url: './reset_pwd.html'
                    },
                    login: {
                        name: 'login',
                        url: './login.html'
                    },
                    main: {
                        name: 'main',
                        url: '../main.html'
                    },
                };
                open_w(winInfo[name].name, winInfo[name].url);
            },
        }
    });

    function send_code(e) {
        var user_tel = $("#user_tel").val();

        if (!checkMobile(user_tel)) {
            $toast("请输入正确的手机号码");
            return false;
        }

        sendsmsLogin(user_tel);

        var s = 60;
        $(e).text(s + 's后重新获取');
        $(e).attr("onclick", "");
        var smstime = setInterval(function() {
            s--;
            $(e).text(s + 's后重新获取');
            if (s == 0) {
                clearInterval(smstime);
                $(e).text("获取验证码");
                $(e).attr("onclick", "send_code(this)");
            }
        }, 1000)
    }

    function sendsmsLogin(user_tel) {
        console.log(user_tel);
        _ajax(Config.api.LoginSendsmsLogin, {
            user_tel: user_tel
        }, function(ret) {
            if (ret.code === 200) {
                $toast('发送成功');
            } else {
                $toast('发送失败');
            }
        });
    }
</script>

</html>
